package com.lanou.controller;

import com.lanou.service.CompanyProductService;
import com.lanou.service.ProductService;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.StrUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/3/13.
 */
@Controller
public class ProductController {
    @Resource
    private ProductService productService;

    @Resource
    private CompanyProductService companyProductService;

    /**
     *
     * @param id 产品Id
     * @return 通过产品Id查询商品详细信息
     * 开发人:孙涛
     */
    @ResponseBody
    @RequestMapping(value = "/selectOneProduct")
    public AjaxResult selectOneProduct(@RequestParam(value = "id", required = false) Integer id) {
        return productService.selectOneProduct(id);
    }

    /**
     *
     * @param pageNum 当前页
     * @param pageSize 当前页显示数据条数
     * @param id 公司id
     * @return 通过公司Id查询公司下所有产品
     * 开发人:孙涛
     */
    @ResponseBody
    @RequestMapping(value = "/pageSelectAllResult")
    public AjaxResult pageSelectAll(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                    @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                    @RequestParam(value = "id", required = false) Integer id) {
        return productService.pageSelectAllResult(pageNum, pageSize, id);

    }

    /**
     * 郭中宏
     * @param companyName 公司名称
     * @return 返回改公司产品中 的家装类型和每个类型的数量
     */
    @ResponseBody
    @RequestMapping(value = "/companyProductHomeTypeCount")
    public AjaxResult companyProductHomeTypeCount(@RequestParam(value = "companyName")String companyName){
        companyName=StrUtils.charSetStr(companyName);
        return new AjaxResult("200","1.0",companyProductService.productHomeTypeCount(companyName));
    }

    /**
     * 郭中宏
     * @param companyName 公司名称
     * @return 返回改公司产品中 的公装类型和每个类型的数量
     */
    @ResponseBody
    @RequestMapping(value = "/productCommonalityTypeCount")
    public AjaxResult productCommonalityTypeCount(@RequestParam(value = "companyName")String companyName){
        companyName=StrUtils.charSetStr(companyName);
        return new AjaxResult("200","1.0",companyProductService.productCommonalityTypeCount(companyName));
    }


    /**
     *
     * @param proStateId 施工状态Id
     * @param pageNum 当前页数
     * @param pageSize 每页显示数据数量
     * @param companyId 公司Id
     * @return 通过施工状态Id分类查询产品
     * 开发人:孙涛
     */
    @ResponseBody
    @RequestMapping(value = "/selectProductByState")
    public AjaxResult selectProductByState(@RequestParam(value = "proStateId", required = false) Integer proStateId,
                                           @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                           @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                           @RequestParam(value = "companyId",required = false)Integer companyId) {
        return productService.pageSelectByStateResult(proStateId,pageNum,pageSize,companyId);
    }

    /*
     * 郭中宏
     * @param companyName 公司名称
     * @param pageNum 当前页数
     * @param pageSize 每页显示的数据个数
     * @return 返回该公司的所有产品（一页）
     */
    @ResponseBody
    @RequestMapping(value = "/companyProductList")
    public AjaxResult companyProductList(@RequestParam(value = "companyName")String companyName,@RequestParam(value = "PageNum",required = false) Integer pageNum,@RequestParam(value = "pageSize",required = false) Integer pageSize){
        companyName=StrUtils.charSetStr(companyName);
        return new AjaxResult("200","1.0",companyProductService.companyProductList(companyName,pageNum,pageSize));
    }

    /**
     * 郭中宏
     * @param companyName 公司名称
     * @param house 产品类型（如：小户型，一局等等）
     * @param pageNo 当前页数
     * @param pageSize 每页显示多少数据
     * @return 返回对应页数的公司产品数据
     */
    @ResponseBody
    @RequestMapping(value = "/companyPrductTypeList")
    public AjaxResult companyPrductTypeList(@RequestParam(value = "companyName")String companyName,@RequestParam(value = "house") String house,@RequestParam(value = "PageNo",required = false) Integer pageNo,@RequestParam(value = "pageSize",required = false) Integer pageSize){
        companyName= StrUtils.charSetStr(companyName);
        house=StrUtils.charSetStr(house);
        return new AjaxResult("200","1.0",companyProductService.companyPrductTypeList(companyName,house,pageNo,pageSize));
    }

    /**
     * 徐鸣
     * 用户添加装修需求数据
     * @param pUserName 用户称呼
     * @param pPhone    用户联系电话
     * @param pCity     用户所在城市
     * @param pDecorateTime 用户装修时间
     * @param pArea     装修面积
     * @param pProductType 房屋类型
     * @param pAddress  房子面积
     */
    @RequestMapping(value = "/insertUserDemand")
    public void insertUserDemand(@RequestParam(value = "pUserName") String pUserName,
                                 @RequestParam(value = "pPhone") String pPhone,
                                 @RequestParam(value = "pCity") String pCity,
                                 @RequestParam(value = "pDecorateTime") String pDecorateTime,
                                 @RequestParam(value = "pArea") String pArea,
                                 @RequestParam(value = "pProductType") String pProductType,
                                 @RequestParam(value = "pAddress") String pAddress){
        System.out.println(pAddress);
        productService.insertUserDemand(pUserName,pPhone,pCity,pDecorateTime,pArea,pProductType,pAddress);
    }

    /**
     *
     * @param productId 产品id
     * @return 此产品的评论信息
     * 开发人:赵帅
     */
    @ResponseBody
    @RequestMapping("/productComments")
    public AjaxResult getUserCommnets(@RequestParam("productId") Integer productId) {
     return productService.getUserComments(productId);
    }
    /**
     * @param productId 产品Id
     * @return 通过产品Id返回施工图片
     * 开发人:孙涛
     */
    @ResponseBody
    @RequestMapping(value = "/selectConstructPhoto")
    public AjaxResult selectConstructPhoto(@RequestParam(value = "productId")Integer productId){
        return productService.selectConstructPhoto(productId);
    }



}
